<template>
  <div class="toutiao-article_item">
    <ul class="articles-content">
      <li class="articles-item">
        <!-- type=1的情况 -->
        <div v-if="article.cover.type === 1" class="item-horizontal">
          <div class="left">
            <!-- 文章标题 -->
            <p class="title">
              {{ article.title }}
            </p>
            <!-- 文章底部 -->
            <p class="bottom_text">
              <span>{{ article.aut_name }}</span>
              <span class="mlr-10">{{ article.comm_count }}评论</span>
              <span>{{ article.pubdate | formatTime }}</span>
            </p>
          </div>
          <!-- 右侧插图 -->
          <div class="right">
            <van-image
              :src="article.cover.images[0]"
              width="3.12rem"
              height="1.94rem"
              fit="cover"
            >
              <template v-slot:error> 图片加载失败 </template>
            </van-image>
          </div>
        </div>

        <!-- type=0和3的情况，没有图片或者三张图片的情况 -->
        <div v-else class="item-column">
          <!-- 文章标题 -->
          <div class="top">{{ article.title }}</div>
          <!-- 中间插图 -->
          <div class="center">
            <van-image
              v-for="(item, index) in article.cover.images"
              :key="index"
              :src="item"
              width="3.12rem"
              height="1.94rem"
              fit="cover"
            >
              <template v-slot:error> 图片加载失败 </template>
            </van-image>
          </div>
          <!-- 文章底部 -->
          <p class="bottom_text">
            <span>{{ article.aut_name }}</span>
            <span class="mlr-10">{{ article.comm_count }}评论</span>
            <span>{{ article.pubdate | formatTime }}</span>
          </p>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  props: {
    // 找父组件要具体的某一条文章数据
    article: {
      type: Object
    }
  }
}
</script>

<style lang="less">
.toutiao-article_item {
  width: 100%;
  .articles-content {
    width: 100%;
    .articles-item {
      width: 100%;
      padding: 10px 20px;
      box-sizing: border-box;
      border-bottom: 1px solid #eee;
      .bottom_text {
        font-size: 20px;
        color: #ccc;
        .mlr-10 {
          margin: 0 10px;
        }
      }
      .item-column {
        .top {
          font-size: 35px;
        }
        .center {
          margin: 10px 0;
          display: flex;
          justify-content: space-between;
        }
      }
      .item-horizontal {
        display: flex;
        justify-content: space-between;
        .left {
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          .title {
            font-size: 35px;
            margin: 0;
            max-width: 450px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
          }
        }
      }
    }
  }
}
</style>
